// ==============================================================================================
// OfficeAppTreeNode.cs
//
// Created by: NI, 2007.03.26
// Revised by: NI, 2007.11.23
// ==============================================================================================
using System.Windows.Forms;
using RibbonExplorer.Entities;
using RibbonExplorer.InfoPanel;

namespace RibbonExplorer.Tree
{
  // ==============================================================================================
  /// <summary>
  /// This tree node represents an Office application in a tree view with its associated ribbons.
  /// </summary>
  // ==============================================================================================
  public abstract class OfficeAppTreeNode : TreeNode, IInfoPanelSupport
  {
    #region Private fields

    private OfficeApp _Application;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates a tree node instance based on the Office application information.
    /// </summary>
    /// <param name="application">Instance describing the Office application</param>
    // --------------------------------------------------------------------------------------------
    public OfficeAppTreeNode(OfficeApp application)
      : base(application.Name)
    {
      // --- Init the application node
      _Application = application;
      ImageKey = _Application.Id;
      SelectedImageKey = ImageKey;
      Tag = _Application;


      // --- Init associated ribbon nodes
      InitRibbons();
      foreach (Ribbon ribbon in _Application.Ribbons)
      {
        Nodes.Add(new RibbonTreeNode(ribbon));      
      }
    }

    #endregion

    #region Public properties

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the object representing application information.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public OfficeApp Application
    {
      get { return _Application; }
    }

    #endregion

    #region Abstract methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Derived classes should override this abstract method to initialize their ribbons.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    protected abstract void InitRibbons();

    #endregion

    #region IInfoPanelSupport implementation

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an infopanel instance for this tree node type.
    /// </summary>
    /// <param name="node">Tree node instance</param>
    /// <param name="navigationService">Navigation service instance</param>
    /// <returns>
    /// User control instance
    /// </returns>
    // --------------------------------------------------------------------------------------------
    public UserControl GetInfoPanelInstance(TreeNode node, INavigationSupport navigationService)
    {
      GenericInfoPanel control = new GenericInfoPanel(navigationService, node);
      control.HeaderText = "Application: " + node.Text;
      return control;
    }

    #endregion
  }
}
